<?php
	
	/*被访者与来访者类*/
	// userid 被访者
	// visitor 来访者
	
	class visitor{
		var $db;
		var $table;
		var $pages;
	
		function __construct()
		{
			global $db, $M, $MODEL;
			$this->db = &$db;
			$this->table = DB_PRE.'member_visitor';	
		}
	
		function visitor()
		{
			$this->__construct();
		}
		
		/*function listinfo($where){
			$data = $this->db->select("SELECT * FROM $this->table WHERE $where");
			return $data;
		}*/
		
		function listinfo($where = '', $page = 1, $pagesize = 20)
		{
			$where = $where ? " WHERE $where " : '';
			$page = max(intval($page), 1);
			$offset = $pagesize*($page-1);
			$limit = " LIMIT $offset, $pagesize";
			
			
			$data = $this->db->select("SELECT count(*) AS `count` FROM `$this->table` $where");
			$number = count($data);
			unset($data);
			
			
			$this->pages = pages($number, $page, $pagesize);
			$array = array();
			$result = $this->db->select("SELECT * FROM `$this->table` $where ORDER BY `addtime` DESC $limit");
			return $result;
		}
		
		function add($userid){
			global $_userid;
			if(!$_userid || $_userid == $userid) return false;
			
			$info = $this->db->get_one("SELECT * FROM `$this->table` WHERE userid = $userid AND visitorid = $_userid");
			
			if($info){
				$data = array('addtime' => TIME);
				return $this->db->update($this->table,$data," userid=$userid AND visitorid = $_userid ");
			}
			else{
				$data = array('userid'=>$userid, 'visitorid' => $_userid, 'addtime' => TIME);
				return $this->db->insert($this->table,$data);
			}
			
		}
		
		function edit(){
		
		}
		
		function delete(){
			
		}
	}
?>